package com.hopu.springmvc.dao.impl;

import com.hopu.springmvc.dao.IUserDAO;
import com.hopu.springmvc.entity.User;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * UserDAO的实现
 */
@Repository
public class UserDAOImpl implements IUserDAO {

    private List<User> users = new ArrayList<>();
    {
        users.add(new User("zhangsan","123","张三",20));
        users.add(new User("lisi","123","李四",20));
        users.add(new User("wangwu","123","王五",20));
        users.add(new User("zhaoliu","123","赵六",20));
        users.add(new User("zhouqi","123","周七",20));
    }

    @Override
    public User login(String username, String password) {
        //模拟数据库查询
        for (User user : users){
            if(user.getUsername().equals(username) && user.getPassword().equals(password)){
                return user;
            }
        }
        return null;
    }

    @Override
    public List<User> queryAllUsers() {
        return users;
    }
}
